var express = require('express');
var router = express.Router();
var query = require('./Database');

/* GET home page. */
router.get('/', function(req, res, next) {
    res.render('ProHistory', {});
});
router.post('/history',async (req,res,next)=>{
    let list = req.body;
    console.log("-----------------");
    let rows = await query("select history.historyid,product.id,product.cartname,product.cartimgsrc,product.cartprice from history join product where history.userid = " + list.userid +" and history.hostate = 1 and history.productid = product.id order by history.historyid desc limit 6");
    console.log("++++++++++++++++");
    console.log(rows);
    let data = [{code:100},rows];
    // res.render(data);
    res.send(data);
    // res.sendFile(data);
})
router.post('/delhistory',async (req,res,next)=>{
    let froData = req.body;
    console.log("-----------------");
    console.log(froData);
    let rows = await query("update history set hostate = 2 where userid = " + froData.userid +" and historyid = " +froData.id);
    console.log("++++++++++++++++");
    console.log(rows);
    let data = [{code:200}];
    // res.render(data);
    res.send(data);
    // res.sendFile(data);
})
module.exports = router;